feat(spec): parse usage comments from strings - #782
Conversation
📝 WalkthroughWalkthroughChangesScript usage parsing
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant ScriptString
participant parse_script_str
participant SharedParser
participant Spec
ScriptString->>parse_script_str: raw script input
parse_script_str->>SharedParser: extract usage markers
SharedParser->>Spec: parse usage specification
Spec-->>parse_script_str: Spec or UsageErr
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Instruction counts
No instruction-count regression above 1%. Only instruction counts gate. Wall clock is shown for context — on identical hardware it moves 4-20% run to run. Measured by tak — instruction-counted CLI benchmarks, stored in this repository's git notes.
|
Greptile SummaryAdds an in-memory script parsing API while preserving file-backed parsing behavior and diagnostics.
Confidence Score: 5/5The PR appears safe to merge. The previously reported relative-include issue is fixed, and no blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "fix(spec): reject relative string includ..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/src/spec/mod.rs`:
- Around line 129-144: Fix parse_script_str and parse_script_with_path so
relative include directives resolve from the intended base path rather than the
repository root. Prefer extending the string-spec API to accept an explicit base
path and pass it into ParsingContext; otherwise keep parse_script_str pathless
and explicitly reject or document relative includes for it, while preserving
path-based resolution in parse_script_with_path.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: f5430be9-5f91-4dda-948d-32147454ef5e
📒 Files selected for processing (1)
lib/src/spec/mod.rs
Summary
Spec::parse_script_strfor parsing embedded USAGE comments from an in-memory scriptThis gives embedders a direct Rust API without requiring a temporary file or deserializing
Spec.Closes #781.
Validation
cargo test -p usage-lib --all-featurescargo clippy -p usage-lib --all-features -- -D warningsNote
Low Risk
Additive public API and clearer errors in spec parsing only; no auth, I/O, or runtime behavior changes beyond new entry points.
Overview
Adds
Spec::parse_script_strso embedders can turn a script body into aSpecwithout writing a temp file or hand-parsing KDL. File-basedparse_scriptnow sharesparse_script_with_pathwith the string API; only the file path still drives defaultbin/nameinference.String parsing uses an empty source path, so relative
includepaths fail with "relative includes require a source file" instead of a parent-directory error. Docs now describe the real markers (#USAGE,//USAGE,::USAGE, and[USAGE]variants) rather than# USAGE:.Tests cover a full embedded script and the relative-include rejection.
Reviewed by Cursor Bugbot for commit 4cc4e74. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
New Features
#USAGE,//USAGE,::USAGE, and[USAGE]markers.Bug Fixes